#!/usr/bin/python
# -*- coding: UTF-8 -*-

__author__ = 'charles'

import psutil
import json
import httplib

processes = {'memcached':'','redis-server':'','nginx':'','mongod':''}
requrl = "http://manage-api.xzsiii.cn/api/monitor/upload_data"
host = "manage-api.xzsiii.cn"

info = {}
cpu_percent = 1.0*psutil.cpu_percent(1,False)
info['cpu_percent'] = cpu_percent

phymem=psutil.virtual_memory()
mem_percent = 1.0*phymem.used/phymem.total
info['mem_percent'] = mem_percent

diskinfo=psutil.disk_usage('/')
disk_percent = 1.0*diskinfo.used/diskinfo.total
info['disk_percent'] = disk_percent


for i in psutil.process_iter():
    if i.name() in processes.keys():
        processes[i.name()] = i.status()

info['processes'] = processes
print info


headerdata = {"Content-type": "application/json"}
conn = httplib.HTTPConnection(host)
conn.request('POST',requrl,json.dumps(info),headerdata)
response = conn.getresponse()
res= response.read()

print res
